//Null 安全是允许您执行以下操作的功能组合：

//显式声明程序中何时允许值。null
fun main1() {
    // neverNull has String type
    var neverNull: String = "This can't be null"

    // Throws a compiler error
//    neverNull = null

    // nullable has nullable String type
    var nullable: String? = "You can keep a null here"

    // This is OK
    nullable = null

    // By default, null values aren't accepted
    var inferredNonNull = "The compiler assumes non-nullable"

    // Throws a compiler error
//    inferredNonNull = null

    // notNull doesn't accept null values
    fun strLength(notNull: String): Int {
        return notNull.length
    }

    println(strLength(neverNull)) // 18
//    println(strLength(nullable))  // Throws a compiler error
}

//检查值。null
fun describeString(maybeString: String?): Int? {
//    使用 Elvis 运算符
    maybeString?.length ?: 0
    return maybeString?.length
}

fun main() {
    var nullString: String? = null
    println(describeString(nullString))
    // Empty or null string
    val listOf = listOf(1, 2, 3)
    listOf?.let {  }
}

//对可能包含值的属性或函数使用安全调用。null

//声明在检测到值时要执行的操作。null